package com.examples.ry.layouts;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;

public class RowLayoutWithFill {
	
	public static void main(String[] args) {
		final Display display = new Display();
		Monitor primary = display.getPrimaryMonitor();
		Rectangle rect = primary.getClientArea();
		Class clazz = RowLayoutWithFill.class;
		Image image = new Image(display,
		clazz.getResourceAsStream("download1.gif"));
		final Shell shell = new Shell(display, SWT.NONE);
		RowLayout layout = new RowLayout();
		layout.type = SWT.VERTICAL;
		layout.fill = true; //Default value is false
		shell.setLayout(layout);
		Label label = new Label(shell, SWT.NONE);
		label.setImage(image);
		final ProgressBar progress =
		new ProgressBar(shell, SWT.NONE);
		shell.pack();
		
		Rectangle bounds = shell.getBounds();
		int x = rect.x
		+ Math.max(0, (rect.width - bounds.width) / 2);
		int y = rect.y
		+ Math.max(0, (rect.height - bounds.height) / 2);
		shell.setBounds(x, y, bounds.width, bounds.height);
		shell.open();
		
		display.timerExec(1000, new Runnable() {
		public void run() {
		int value = progress.getSelection();
		if (value < 100) {
		progress.setSelection(value + 10);
		display.timerExec(1000, this);
		} else {
		shell.dispose();
		}
		}
		});
		while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
		}
		image.dispose();
		display.dispose();
		}

}
